OPENING QUESTIONS: Can you suggest an instance when it might be VERY helpful to use a global variable?
OBJECTIVES:
- I will be able to explain the difference between system variables, global variables and script variables after today's class
WORD FOR TODAY:
- system variable (a data bucket provided by SNAP)
- variable (a user-defined data bucket)
- global variable (available EVERYWHERE)
- script variable (PRIVATE)
TIPS O' THE DAY:
1) ALWAYS have a 'clear' button (
) on hand... it makes clearing the screen much easier than having to hunt for it.
2) You can also 'delete' a script by dragging it off the scripting area
3) If you know the name of a block but can't remember where it is, use the ALWAYS helpful ctrl-F key (that works on web sites AND pdf documents by the way)
4) How can you *duplicate* a script or part of a script (this will be VERY helpful in today's lab)
5) Always a good idea to have an x 'go to 0' and a y 'go to 0' to re-center your sprite if it get's lost
6) Right Mouse click on the stage and select 'show all' to bring sprite(s) back
WORK O' THE DAY:
Very quickly -- please write down a list of our "BEST PRACTICES"
Compare your list to your group... do they match?
Any questions, comments or concerns about our list so far? (Some of which we haven't put into practice, oddly enough)
═══════════════════════════
Create two sprites
Change the costume of each sprite to... your choice!
Write a script that uses GLOBAL variables to communicate between your sprites like this:
═══════════════════════════
Try it for 10 - 15 minutes and then we'll talk about some of the specific code pieces...
═══════════════════════════
Notice that I've used the
block to make sure that both sprites are executing code...
What do you suppose happens when I remove the
block from the second sprit?
Now try it, remove that block and see what happens...
Now put it back and open the first sprite's script.... try clicking on the code and notice that it doesn't execute entirely.... why is that?
═══════════════════════════
Notice that I've used the immensely powerful
block.
Instructions inside that block will "Loop" (that's the programming term) forever. Needless to say you MUST be careful how you use that block since you may end up with the dreaded "Infinite Loop" which can crash your program, and in some cases, crash your browser, and hopefully not but once in a while crash your computer... not good.
Fortunately, I can always hit the red flag button
to stop my program from running.
However, if I've written a program for other 'users', then I really need to have a more elegant way for my program to stop...we'll talk about that soon.
Now let's look at the code: